package conversores;

import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.convert.ConverterException;

public class DescricaoConverter implements Converter {

	@Override
	public Object getAsObject(FacesContext fc, UIComponent uic, String val) throws ConverterException{
		if (val == null || val.trim().equals("")) {
			return null;
		} 
		return val;
	}

	@Override
	public String getAsString(FacesContext fc, UIComponent uic, Object val) throws ConverterException{
		if ((val == null) || (val.toString().trim().equals(""))) 
			return "";
		String desc = val.toString();
		String descReduzida;
		if (desc.length() > 35)
			descReduzida = desc.substring(0, 34) + " . . . ";
		else
			descReduzida = desc;
		return descReduzida;		
	}

}
